Skip to content

Add general signal hook but keep pari #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

mkoeppe
Copy link

@mkoeppe mkoeppe commented Sep 21, 2023

Introduces a general hook as proposed in the discussion of sagemath/cypari2#109.

Split out from #166. @kliem @videlec

@mkoeppe mkoeppe added this to the 1.11.3 milestone Sep 21, 2023
@mkoeppe mkoeppe force-pushed the add_general_signal_hook_but_keep_pari branch from acd9d8b to 2c32e71 Compare September 21, 2023 17:29
@mkoeppe mkoeppe force-pushed the add_general_signal_hook_but_keep_pari branch from 2c32e71 to fed466d Compare September 21, 2023 21:16
@mkoeppe
Copy link
Author

mkoeppe commented Sep 21, 2023

@malb @dimpase Let's merge this please

Copy link
Member

@dimpase dimpase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it something untested?

@mkoeppe
Copy link
Author

mkoeppe commented Sep 22, 2023

Yes, this has already been tested, and the corresponding PR sagemath/cypari2#117 was already merged (.... by you, @dimpase) into cypari2, until someone decided to back it out again without discussion. sagemath/cypari2#130 has the change on the cypari2 side of things again.

Here I am using an approach that needs less coordination. Keeping the cypari2-specific code (so that current cypari2 works) and adding a general hook (so that future cypari2 with sagemath/cypari2#130 can work).

@dimpase dimpase merged commit 1adcbd9 into sagemath:main Sep 25, 2023
@mkoeppe mkoeppe deleted the add_general_signal_hook_but_keep_pari branch September 25, 2023 16:48
@@ -400,6 +432,7 @@ static void _sig_on_interrupt_received(void)
cysigs.sig_on_count = 0;
cysigs.interrupt_received = 0;
PARI_SIGINT_pending = 0;
custom_signal_unblock();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a typo in this line: it should have been

    custom_set_pending_signal(0);

instead.

In fact, I was having some issues with cysignals 1.12.2 (some doctest failures having to do with alarms, etc) and changing this seems to sovle them.

@kliem can you confirm this is correct?

@antonio-rojas I think this is the fix we were missing. I'm testing, will do a PR tomorrow. Because of the PARI_SIGINT_pending = 0; line, the typo doesn't cause trouble (i.e., until that line is removed).

To be clear, this is the patch I'm testing on top of 1.12.2:

--- a/src/cysignals/implementation.c
+++ b/src/cysignals/implementation.c
@@ -591,7 +591,7 @@ static void _sig_on_interrupt_received(void)
     do_raise_exception(cysigs.interrupt_received);
     cysigs.sig_on_count = 0;
     cysigs.interrupt_received = 0;
-    custom_signal_unblock();
+    custom_set_pending_signal(0);
 
 #if HAVE_SIGPROCMASK
     sigprocmask(SIG_SETMASK, &oldset, NULL);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't quite work for me. Now instead of crashing, tests hang and timeout after 30 minutes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything works "fine" for me (still getting occasional random failures, but that's not new).

The only difference between cysignals 1.11.4 and 1.12.2 in this respect is this change. Although with 1.11.4, in effect, it is both custom_set_pending_signal(0); and custom_signal_unblock(); but I don't think the unblock there is correct.

Are you using sagemath/cypari2#167 (included in cypari2 2.2.1)? This could make a difference, maybe. I'm not sure if this code is compiled with legacy_implicit_noexcept, you could check the generated .c file to see if it's "clean" as it should be.

The other patch I'm using on cysignals (already for 1.11.4) is: https://github.com/void-linux/void-packages/blob/master/srcpkgs/python3-cysignals/patches/verify_exc_value.patch

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using sagemath/cypari2#167 (included in cypari2 2.2.1)? This could make a difference, maybe. I'm not sure if this code is compiled with legacy_implicit_noexcept, you could check the generated .c file to see if it's "clean" as it should be.

I'm getting the same with cypari2 2.2.0 (+pari 2.17 patches)

Copy link
Member

@dimpase dimpase Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've released cypari2 2.2.1 - which supports pari 2.17

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, not sure what happened before (possibly some memory issues), but it seems to be working now, except that the random failure I reported in sagemath/sage#38749 (comment) is now permanent (regardless of the used seed)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, not sure what happened before (possibly some memory issues), but it seems to be working now, except that the random failure I reported in sagemath/sage#38749 (comment) is now permanent (regardless of the used seed)

Great! I have a PR almost ready to submit (including a test to trigger this bug with cypari2).

As for the remaining issue, I'm getting the same, and I'm working on it. This appears to be related to #215. The implementation of sig_occurred() seems to be incorrect, in the sense that sig_occurred() will sometimes return an old exception that has been already handled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a basically a 1-line PR (+ the test)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a basically a 1-line PR (+ the test)?

Yes, I wanted to test it further. I'm also working on the remaining issue which seems more tricky, but I think I have a reasonable fix. Hopefully this might get rid of all the stupid heisenbugs that have been pestering us.

I was actually trying to push this to GH a moment ago, but it seems there is a major outage right now (git pull/push from/to github, are not working atm).

tornaria added a commit to tornaria/cysignals that referenced this pull request Jan 14, 2025
There was a typo in sagemath#181: when the pari sigint handling was converted
to a general mechanism, the line

```
    PARI_SIGINT_pending = 0;
```

got translated into

```
    custom_signal_unblock();
```
instead of the correct
```
    custom_set_pending_signal(0);
```

This error didn't take effect until sagemath#166 removed the pari sigint
handling.

This causes some doctest failures in sagemath:
```
src/sage/coding/linear_code.py
src/sage/geometry/integral_points.pxi
src/sage/rings/integer.pyx
src/sage/rings/polynomial/polynomial_element.pyx
```
related to mishandling of AlarmInterrupt.

See: https://github.com/sagemath/cysignals/pull/181/files#r1904885037
dimpase pushed a commit that referenced this pull request Jan 14, 2025
There was a typo in #181: when the pari sigint handling was converted
to a general mechanism, the line

```
    PARI_SIGINT_pending = 0;
```

got translated into

```
    custom_signal_unblock();
```
instead of the correct
```
    custom_set_pending_signal(0);
```

This error didn't take effect until #166 removed the pari sigint
handling.

This causes some doctest failures in sagemath:
```
src/sage/coding/linear_code.py
src/sage/geometry/integral_points.pxi
src/sage/rings/integer.pyx
src/sage/rings/polynomial/polynomial_element.pyx
```
related to mishandling of AlarmInterrupt.

See: https://github.com/sagemath/cysignals/pull/181/files#r1904885037
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants